<template>
	<view class="bgcolor">
		<view style="margin:0 auto ;width:calc(100% - 38rpx);">
			<view class="flexaround my-head" @click="gotoInfo()">
				<view class="nick">
					<!-- 头像 -->
					<image :src="userinfo.avatar_text" mode="" style="width: 160rpx;height: 160rpx;"></image>
				</view>
				<view style="width: 60%;" v-if="is_login==true?true:false">
					<text style="font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 800;
					color: #000000;">{{userinfo.username==null?"":userinfo.username}}</text>
					<view style="font-size: 30rpx;
					margin-top: 30rpx;
					font-family: PingFang SC;
					font-weight: 800;
					color: #999999;" v-show="userinfo.gongsi">{{userinfo.gongsi}}</view>
				</view>
				<view style="width: 60%; font-size: 45rpx;font-weight: 500;" v-if="is_login==false?true:false">未登录</view>
				<view>
					<u-icon name='arrow-right' size="28"></u-icon>
				</view>
			</view>
			<view class="zhye-cont">
				<view class="flexbetween">
					<text style="margin-left: 59rpx;">账户余额（元）</text>
					<view class="" style="width: 50%;text-align: right;">
						<text class="look" @click="lookMoney">查看</text>
					</view>
				</view>
				<view class="money">{{is_login?userinfo.money:'0.00'}}</view>
			</view>
			<view class="menus">
				<view v-for="(item,index) in menu" :key="index" style="display: flex;" @click="gotofn(item.id)">
					<view class="left-menu">
						<u-icon :name='item.icon' size="28" color="#333" style='margin-right: 28rpx;'></u-icon>
						<text class="tit">{{item.title}}</text>
						<u-icon name='arrow-right' style='margin-right: 20rpx;'></u-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				menu: [{
						title: '银行卡信息',
						icon: "coupon",
						id:0
					},
					// {
					// 	title: '常见问题',
					// 	icon: require('@/static/imags/mypage/a02.png')
					// },
					{
						title: '意见反馈',
						icon: "order",
						id:1
					}, {
						title: '有困难找推荐人:',
						icon: "kefu-ermai",
						id:2
						// icon:""
					}, {
						title: '关于我们',
						icon: "info-circle",
						id:3
					}, {
						title: '设置',
						icon: "setting",
						id:4
					}
				],
				is_login: false,
				userinfo: {
					nickname:"",
					money:"",
					gongsi:"",
				},
				contact:"",
				once:false,
			}
		},
		onShow() {
			this.is_login = httpRequest.checkIsLogin();
			if (this.is_login) {
				this.getinfo()
				this.getMessage()
			}
		},
		methods: {
			getMessage(){ //消息未读数量
				console.log()
				let _this = this;
				httpRequest.request('/employeesapi/index/newsNoReadNum', 'GET', {
					
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.info=res.data
						if(res.data.total_noread_num!=0){
							uni.setTabBarBadge({
								index: 1,
								text: res.data.total_noread_num
							})
						}else{
							uni.removeTabBarBadge({
								index:1
							})
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// 个人信息
			getinfo() {
				httpRequest.request('/employeesapi/user/index', 'POST', {
				}).then(res => {
					this.userinfo = res.data
					if(this.once){
						return
					}
					if(res.data.rec_userinfo){
						this.menu[2].title = this.menu[2].title+res.data.rec_userinfo.nickname
						this.contact =  res.data.rec_userinfo.mobile
					}else{
						this.menu.splice(2,1)
					}
					this.once = true
					
				})
			},
			gotoInfo() {
				if (!this.is_login) {
					uni.navigateTo({
						url: '/pages/thelogin/thelogin?msg=1'
					})
					return false
				}
				uni.navigateTo({
					url: './myInfo'
				})
			},
			gotofn(i) {
				if (i == 0) {
					uni.navigateTo({
						url: '/pages/mypage/addBackInfo'
					})
				}
				if (i == 1) {
					uni.navigateTo({
						url: './opinion'
					})
				}
				if (i == 2) {
					let _this = this
					uni.makePhoneCall({
						phoneNumber: _this.contact.toString()
					}).catch((e) => {
						// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
					})
				}
				if (i == 3) {
					uni.navigateTo({
						url:"/pages/mypage/about?msg=1"
					})
				}
				if (i == 4) {
					uni.navigateTo({
						url: './set'
					})
				}

			},
			lookMoney() {
				uni.navigateTo({
					url: './lookMoney'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-head {
		margin: 0 auto;
		padding-top: 80px;

		.nick {
			width: 160rpx;
			height: 160rpx;
			border-radius: 50%;
			overflow: hidden;
		}
	}

	.zhye-cont {
		margin-top: 40rpx;
		background-color: #fff;
		// height: 130rpx; 
		padding: 40rpx 20rpx 50rpx 0;
		box-sizing: border-box;
		border-radius: 5px;

		.look {
			width: 100%;
			height: 68rpx;
			background: #3476fe;
			border-radius: 34rpx;
			text-align: center;
			color: #fff;
			line-height: 68rpx;
			padding: 10rpx 30rpx;
			font-weight: 800;
			font-size: 30rpx;
		}

		.money {
			font-weight: bold;
			font-size: 56rpx;
			margin: 40rpx 0 0rpx 61rpx;
		}
	}

	.menus {
		padding: 0;
		margin-top: 40rpx;
		background-color: #fff;
		border-radius: 5px;

		.left-menu {
			height: 120rpx;
			// line-height: 140rpx;
			padding: 0 50rpx;
			width: 100%;
			font-size: 36rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid #F6F6F6;
			box-sizing: border-box;

			.imgs {
				width: 7%;
			}

			.tit {
				width: 77%;
				text-align: left;
			}
		}

	}
</style>
